package com.somsoft.handjc.activity.query.xuncha;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.somsoft.handjc.activity.R;
import com.somsoft.handjc.util.BaseActivity;
import com.somsoft.handjc.util.MyApplication;
import com.somsoft.handjc.util.Utils;
import com.somsoft.handjc.util.XunChaDataUtil;

/**
 * 案件信息查询
 * 
 * @author Administrator
 * 
 */
@SuppressWarnings("all")
public class ZhongHeQueryDetailActivity extends BaseActivity {

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		MyApplication.getInstance().addActivity(this);
		setTitle("业务信息明细");
		setContentView(R.layout.xuncha_zhonghe_query_detail);
		try {
			Intent it = getIntent();
			final String busiId = it.getStringExtra("busiId");
			getData(busiId);
			Button btn = (Button)findViewById(R.id.btnStage); 
			btn.setOnClickListener(new OnClickListener(){
				@Override
				public void onClick(View v) {
					Utils.openLoading(ZhongHeQueryDetailActivity.this);
					Intent it = new Intent(ZhongHeQueryDetailActivity.this,ZhongHeQueryFeedbackActivity.class);
					it.putExtra("busiId", busiId);
					startActivity(it);
				}
			});
			//"stageTarget","stageDate","stageDays","descs","feedbackTime","finishStatus","feedFiles"
			//R.id.stageTarget,R.id.stageDate,R.id.stageDays,R.id.descs,R.id.feedbackTime,R.id.finishStatus,R.id.feedFiles
//			SimpleAdapter adapter = new SimpleAdapter(this, getData(busiId),
//					R.layout.xuncha_zhonghe_query_detail,
//					new String[] { "projectName", "projectCode", "deptName" ,"deptPhone","leaderName","leaderJob","leaderPhone","touzhiType",
//				"deptContact","totalTouzhi","finishTouzhi","finished","projectLevel","timeLimitJcResultImg","abnormalJcResultImg","patrolJcResultImg","finalResultImg"},
//					new int[] { R.id.projectName, R.id.projectCode, R.id.deptName ,R.id.deptPhone,R.id.leaderName,R.id.leaderJob,R.id.leaderPhone,R.id.touzhiType,
//				R.id.deptContact,R.id.totalTouzhi,R.id.finishTouzhi,R.id.finished,R.id.projectLevel,R.id.timeLimitJcResultImg,R.id.abnormalJcResultImg,R.id.patrolJcResultImg,R.id.finalResultImg
//				});
//			setListAdapter(adapter);
		} catch (Exception e) {
			Toast.makeText(ZhongHeQueryDetailActivity.this, "加载数据失败！", Toast.LENGTH_SHORT).show();
		}
		Utils.closeLoading();
	}
	
	private List<Map<String, Object>> getData(String busiId) throws Exception{
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("filter_EQS_id",busiId));
		
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		try {
			JSONArray array = XunChaDataUtil.getBusinessInfo(params);
			Map<String, Object> map = null;
			for(int i = 0; i < array.length(); i++){
				JSONObject obj = array.getJSONObject(i);
				map = new HashMap<String, Object>(); 
				map.put("busiId", obj.getString("id"));
				map.put("projectName", "业务名称："+obj.getString("projectName"));
				map.put("projectCode", "业务编号："+obj.getString("projectCode"));
				map.put("deptName", "责任单位："+obj.getString("deptName"));
				
				map.put("deptPhone", "责任单位电话："+obj.getString("deptPhone"));
				map.put("leaderName", "责任区领导："+obj.getString("leaderName"));
				map.put("leaderJob", "责任区领导身份："+obj.getString("leaderJob"));
				map.put("leaderPhone", "责任区领导电话："+obj.getString("leaderPhone"));
				map.put("touzhiType", "投资类型："+obj.getString("touzhiType"));
				
				map.put("deptContact", "责任单位联系人："+obj.getString("deptContact"));
				map.put("totalTouzhi", "总投资："+obj.getString("totalTouzhi")+"万元");
				map.put("finishTouzhi", "完成投资："+obj.getString("finishTouzhi")+"万元");
				map.put("finished", "项目是否完成："+obj.getString("finished"));
				map.put("projectLevel", "项目类型："+obj.getString("projectLevel"));
				
				String timeLimitJcResult = obj.getString("timeLimitJcResult");
				String abnormalJcResult = obj.getString("abnormalJcResult");
				String patrolJcResult = obj.getString("patrolJcResult");
				String finalResult = obj.getString("finalResult");
				if("NORMAL".equals(timeLimitJcResult)){
					map.put("timeLimitJcResultImg", R.drawable.normal);
					((ImageView)findViewById(R.id.timeLimitJcResultImg)).setImageResource(R.drawable.normal);
				}else if("YELLOW".equals(timeLimitJcResult)){
					map.put("timeLimitJcResultImg", R.drawable.yellow);
					((ImageView)findViewById(R.id.timeLimitJcResultImg)).setImageResource(R.drawable.yellow);
				}else if("RED".equals(timeLimitJcResult)){
					map.put("timeLimitJcResultImg", R.drawable.red);
					((ImageView)findViewById(R.id.timeLimitJcResultImg)).setImageResource(R.drawable.red);
				}
				
				if("NORMAL".equals(abnormalJcResult)){
					map.put("abnormalJcResultImg", R.drawable.normal);
					((ImageView)findViewById(R.id.abnormalJcResultImg)).setImageResource(R.drawable.normal);
				}else if("YELLOW".equals(abnormalJcResult)){
					map.put("abnormalJcResultImg", R.drawable.yellow);
					((ImageView)findViewById(R.id.abnormalJcResultImg)).setImageResource(R.drawable.yellow);
				}else if("RED".equals(abnormalJcResult)){
					map.put("abnormalJcResultImg", R.drawable.red);
					((ImageView)findViewById(R.id.abnormalJcResultImg)).setImageResource(R.drawable.red);
				}
				
				if("NORMAL".equals(patrolJcResult) || "NOT".equals(patrolJcResult)){
					map.put("patrolJcResultImg", R.drawable.normal);
					((ImageView)findViewById(R.id.patrolJcResultImg)).setImageResource(R.drawable.normal);
				}else if("YELLOW".equals(patrolJcResult)){
					map.put("patrolJcResultImg", R.drawable.yellow);
					((ImageView)findViewById(R.id.patrolJcResultImg)).setImageResource(R.drawable.yellow);
				}else if("RED".equals(patrolJcResult)){
					map.put("patrolJcResultImg", R.drawable.red);
					((ImageView)findViewById(R.id.patrolJcResultImg)).setImageResource(R.drawable.red);
				}
				
				if("NORMAL".equals(finalResult)){
					map.put("finalResultImg", R.drawable.normal);
					((ImageView)findViewById(R.id.finalResultImg)).setImageResource(R.drawable.normal);
				}else if("YELLOW".equals(finalResult)){
					map.put("finalResultImg", R.drawable.yellow);
					((ImageView)findViewById(R.id.finalResultImg)).setImageResource(R.drawable.yellow);
				}else if("RED".equals(finalResult)){
					map.put("finalResultImg", R.drawable.red);
					((ImageView)findViewById(R.id.finalResultImg)).setImageResource(R.drawable.red);
				}
				
				
				((TextView)findViewById(R.id.busiId)).setText(map.get("busiId").toString());
				((TextView)findViewById(R.id.projectName)).setText(map.get("projectName").toString());
				((TextView)findViewById(R.id.projectCode)).setText(map.get("projectCode").toString());
				((TextView)findViewById(R.id.deptName)).setText(map.get("deptName").toString());
				((TextView)findViewById(R.id.deptContact)).setText(map.get("deptContact").toString());
				((TextView)findViewById(R.id.deptPhone)).setText(map.get("deptPhone").toString());
				((TextView)findViewById(R.id.leaderName)).setText(map.get("leaderName").toString());
				((TextView)findViewById(R.id.leaderJob)).setText(map.get("leaderJob").toString());
				((TextView)findViewById(R.id.leaderPhone)).setText(map.get("leaderPhone").toString());
				((TextView)findViewById(R.id.touzhiType)).setText(map.get("touzhiType").toString());
				((TextView)findViewById(R.id.totalTouzhi)).setText(map.get("totalTouzhi").toString());
				((TextView)findViewById(R.id.finishTouzhi)).setText(map.get("finishTouzhi").toString());
				((TextView)findViewById(R.id.finished)).setText(map.get("finished").toString());
				((TextView)findViewById(R.id.projectLevel)).setText(map.get("projectLevel").toString());
				
				list.add(map);
			}
		} catch (Exception e) {
			throw e;
		}
		return list;

	}


}
